<%--
  Author      : MadFrog
  Date        : 2018/10/9 15:53
  Description : 教职工签到页面
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>签到</title>
    <%@include file="../common/_head.jsp" %>
</head>
<body ontouchstart>
<div class="weui-cells">
    <c:forEach items="${signInList }" var="signIn">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input type="hidden" id="signInId" value=${signIn.id }>
                <p>${signIn.title }</p>
            </div>
            <div class="weui-cell__ft">
                <a href="javascript:;" id="signIn" class="weui-btn weui-btn_mini weui-btn_primary">签到</a>
                <a href="javascript:;" id="leave" class="weui-btn weui-btn_mini weui-btn_primary">请假</a>
            </div>
        </div>
    </c:forEach>
</div>
<%@include file="../common/_foot.jsp" %>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript" src="${ctx}/resources/wechat/js/wxConfig.js"></script>
<script>
    var gps;
    wx.ready(function () {
        wx.getLocation({
            type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
            success: function (res) {
                // 注册“我要签到”按钮点击事件
                gps = res;
            },
            failure: function () {
                alert("微信JSSDK-getLocation()失败");
            }
        });
    });
    $(document).on("click", "#signIn", function () {
        $.confirm("确认当前地点无误", "确认签到", function () {
            var params = {};
            signIn(params);
        }, function () {

        });
    });
    $(document).on("click", "#leave", function () {
        $.prompt({
            title: "请简要输入请假原因",
            onOK: function (text) {
                var params = {};
                params.description = text;
                signIn(params);
            },
            onCancel: function () {
            }
        });
    });

    function signIn(params) {
        params.signInId = $("#signInId").val();
        params.latitude = gps.latitude;
        params.longitude = gps.longitude;
        $.ajax({
            type: "post",
            url: "${ctx}/teacher/userSignIn/signIn",
            data: params,
            dataType: "json",
            success: function (re) {
                if (true == re.success) {
                    $.toast("操作成功", function () {
                        window.location = "${ctx}/teacher/index";
                    });
                } else {
                    $.toast("后台错误，请联系管理员", "cancel");
                }
            },
            error: function (re) {
                $.toast("网络请求失败，请联系管理员", "cancel");
            }
        });
    }
</script>
</body>
</html>